//
//  LookParameterViewController.m
//  PrintPort
//
//  Created by hy002 on 2018/1/25.
//  Copyright © 2018年 HUAYU. All rights reserved.
//

#import "LookParameterViewController.h"
#import "ParameterModel.h"

static NSString *cellPath = @"LookParameterCell";
@interface LookParameterViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong)UITableView *tableview;
@property (nonatomic, strong)NSArray *allValueAry;

@end

@implementation LookParameterViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.hidden = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatUI];
    [self requestLookParamer];
    
}

- (void)creatUI
{
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.title = @"产品参数";
    self.view.backgroundColor = BacksColor;
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-STA_NAV_HEIGHT) style:UITableViewStylePlain];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableview.backgroundColor = BacksColor;
    [self.view addSubview:_tableview];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _allValueAry.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellPath];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (_allValueAry.count > 0)
    {
        ParameterModel *model = _allValueAry[indexPath.row];
        UILabel *nameLab = [ZCControl createLabelWithFrame:CGRectMake(0, 5*displaywidth, 100*displaywidth, 35*displaywidth) Font:14.0 Text:model.parameterName Color:BlaTiColor];
        nameLab.textAlignment = NSTextAlignmentCenter;
        [cell.contentView addSubview:nameLab];
        UILabel *valueLab = [ZCControl createLabelWithFrame:CGRectMake(100, 5*displaywidth, SCREEN_WIDTH-100*displaywidth, 35*displaywidth) Font:14.0 Text:model.parameterValue Color:BlaTiColor];
        valueLab.textAlignment = NSTextAlignmentCenter;
        [cell.contentView addSubview:valueLab];
        UIView *lineAview = [[UIView alloc] initWithFrame:CGRectMake(0, 44*displaywidth, SCREEN_WIDTH, 1*displaywidth)];
        lineAview.backgroundColor = LinesColor;
        [cell.contentView addSubview:lineAview];
        UIView *lineBview = [[UIView alloc] initWithFrame:CGRectMake(100*displaywidth, 0, 1*displaywidth, 45*displaywidth)];
        lineBview.backgroundColor = LinesColor;
        [cell.contentView addSubview:lineBview];
    }
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 45*displaywidth;
}

- (void)requestLookParamer
{
    WEAKSELF;
    NSDictionary *dic = @{@"productSizeDetailId":_parmerID};
    [HYBaseHandler requestWithTheFormUrl:SERVER_lookParameter Parmers:dic Success:^(id obj) {
        if ([obj server_Getcodecheck])
        {
            _allValueAry = [ParameterModel mj_objectArrayWithKeyValuesArray:obj[@"data"]];
            dispatch_async(dispatch_get_main_queue(), ^{
                [weakSelf.tableview reloadData];
            });
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
    } failed:^(NSError *error) {
        
    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
